// pages/mySelf/mySelf.js
const app = getApp()

Page({
  /**
   * 页面的初始数据
   */
  data: {
    userInfo: {
      // avatarUrl: '../../image/nav/task.png',
      // nickName:'小马哥'
    },
    userLevel: '高级佣兵',
    money: 0,
    score: 0.0,
    integral: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      userInfo: app.globalData.userInfo,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.request({
      url: app.globalData.prefix + "/memberAction/memberCenter.do",
      data: {
        openId: app.globalData.userInfo.openId
      },
      success: (res) => {
        let status = res.data.status
        if (status == "00") {
          let data = res.data.result
          this.data.userInfo.nickName = data.nickName
          this.data.userInfo.avatarUrl = data.avatarUrl
          this.setData({
            userInfo: this.data.userInfo,
            userLevel: data.level,
            money: data.money,
            score: data.score,
            integral: data.integral
          })
        } else {
          wx.$showToast(res.data.errorMsg)
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    console.log(res);
    return {
      // title: '转发!!!!!!!!!!!!',
      path: '/pages/logs/logs',
      // imageUrl:'',
      success: function (res) {
        alert('成功')
        console.log('成功', res)
      }
    }
  },
  go(e) {
    let url = e.currentTarget.dataset.src
    if (url == '../solidList/solidList') {
      wx.request({
        url: app.globalData.prefix + "/corpsAction/isInCrops.do",
        data: {
          openId: app.globalData.userInfo.openId
        },
        success: (res) => {
          let status = res.data.status
          if (status == "00") {
            let data = res.data.result
            if (data) {
              url = '../myArmy/myArmy'
            }
            wx.navigateTo({
              url: url,
            })
          }
        }
      })
    } else {
      wx.navigateTo({
        url: url,
      })
    }
  }
})